<?php
class User_model extends CI_Model{
	public function select($user,$pass){
		$query = $this->db->get_where('users',array('user_login' => $user,'user_pass' => md5($pass)));
		$object = null;
		if($query->num_rows()){
			$object = $query->result();	
		}
		
		$query->free_result();
		return $object[0];
	}
	
	public function getUserById($id){
		$query = $this->db->get_where('users',array("ID" => $id));
		$object = NULL;
		if($query->num_rows()){
			$object = $query->result();
		}
		
		$query->free_result();
		return $object[0];
	}
	
	public function insert($user,$pass,$name,$email,$address,$phone){
		$data = array(
			'user_login' => $user,
			'user_pass' => md5($pass),
			'user_name' => $name,
			'user_email' => $email,
			'user_address' => $address,
			'user_phone' => $phone,
			'user_status' => 1
		);
		
		try {
			$this->db->insert('users',$data);
		} catch (Exception $e) {
			return 0;
		}
		return 1;
	}
}